#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: 
@time: 2024/2/28 9:52 PM
@Function: 请输入模块功能描述
"""
import logging
import os.path
import yaml


class Logger:
    def __init__(self,path: str='./'):
        if not os.path.isfile(path+'lib/conf.yaml'):
            path='../'

        with open(file = path+'lib/conf.yaml',mode = 'r',encoding = 'utf-8')as file:
            logging_yaml=yaml.safe_load(stream = file).get('logger')
            logging_yaml['filename']=path+logging_yaml.get('filename')
            logging.basicConfig(**logging_yaml)

        #根据根记录器，配置信息从yaml文件中获取
        self.logger=logging.getLogger()
        #创建输出到控制台
        console=logging.StreamHandler
        #设置日志级别
        console.setLevel(logging_yaml['level'])
        #设置日志格式
        console.setFormatter(logging.Formatter(logging_yaml['format']))
        #添加到log输出
        self.logger.addHandler(console)

    def debug(self,msg:str=''):
        self.logger.debug(msg)

    def info(self,msg:str=''):
        self.logger.info(msg)

    def warning(self,msg:str=''):
        self.logger.warning(msg)

    def error(self,msg:str=''):
        self.logger.error(msg)

    def exception(self,e):
        self.logger.exception(e)

logger=Logger()